package com.ddzh.web;


import com.ddzh.dto.RoleDto;
import com.ddzh.dto.UserRoleDto;
import com.ddzh.entity.Result;
import com.ddzh.pojo.Role;
import com.ddzh.service.CheckGroupItemService;
import com.ddzh.service.UserRoleService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userRoleController")
public class UserRoleController {

    @Reference //这里夸项目访问=》夸IoC容器访问=》夸服务器后台访问数据
    private UserRoleService userRoleService;

    @GetMapping("/findRoleIdsByUserId/{userId}")//用的是动态传参：请求路径直接给一个数据即可不用key=value格式
    public Result findRoleIdsByUserId(@PathVariable("userId") Long userId){
        System.out.println("userId = " + userId);
        Result result = new Result(userRoleService.findRoleIdsByUserId(userId));
        System.out.println("result.getData().toString() = " + result.getData().toString());
        return  result;
    }

    @PostMapping("/allocateRole")
    public Result allocateRole(@RequestBody UserRoleDto userRoleDto){
        return new Result(userRoleService.allocateRole(userRoleDto));
    }

    @GetMapping("/findUserIdsByRoleId/{roleId}")
    public Result findUserIdsByRoleId(@PathVariable("roleId") Long roleId){
        return new Result(userRoleService.findUserIdsByRoleId(roleId));
    }


    @PostMapping("/allocateUser")
    public Result allocateUser(@RequestBody UserRoleDto userRoleDto){
        return new Result(userRoleService.allocateUser(userRoleDto));
    }
}
